<?php include "./pc/view/header.inc.htm"; ?>

<div class="container">
    <div class="content" id="threadlist_panel">
        <div class="content-header">
            <div class="tw-header-inner">
                <h2>个人资料</h2>
            </div>
        </div>
        <div class="content-body">
            <div class="reply-form">
                <div class="reply-inner">
                    <div class="topic-content">
                        <div class="topic-user">
                            <img src="<?php echo $_user['avatar_url']; ?>" class="avatar" alt="<?php echo $_user['username']; ?>" title="<?php echo $_user['username']; ?>">
                            <strong>
                                <?php echo $_user['username']; ?>
                            </strong>
                            <small>
                                我就是我，不一样的烟火~
                            </small>
                        </div>
                    </div>
                </div>
            </div>
            <div class="content-inner">

            <?php if($_user['uid'] > 0) { ?>

                <dl class="user-profile">
                    <dt>用户名</dt>
                    <dd><?php echo $_user['username']; ?></dd>
                    <dt>用户组</dt>
                    <dd><?php echo $_user['groupname']; ?></dd>

                    <dt>主题</dt>
                    <dd><?php echo $_user['threads']; ?></dd>
                    <dt>帖子</dt>
                    <dd><?php echo $_user['posts']; ?></dd>
                    <dt>被喜欢</dt>
                    <dd><?php echo $_user['agrees']; ?></dd>

                    <?php if($group['allowviewip']) { ?>
                    <dt>邮箱</dt>
                    <dd><?php echo $_user['email']; ?></dd>
                    <dt>注册IP</dt>
                    <dd><?php echo $_user['create_ip_fmt']; ?><span class="point">·</span><?php echo ($banip ? '[禁止至：'.$banip['expiry_fmt'].']' : ''); ?></dd>
                    <?php } ?>

                    <?php if(!empty($group['allowbanuser'])) { ?>
                    <dt class="mt10">
                        <select id="day_<?php echo $_ip_url; ?>">
                            <option value="1">一天</option>
                            <option value="3">三天</option>
                            <option value="7">一周</option>
                            <option value="30">一月</option>
                            <option value="365">一年</option>
                            <option value="0">永久禁止</option>
                            <option value="-1">解除禁止</option>
                        </select>
                    </dt>
                    <dd class="mt10">
                        <button class="Button Button-primary" id="user_banip_<?php echo $_ip_url; ?>">禁止/解除注册 IP</button>
                    </dd>
                    <?php } ?>

                    <?php if(!empty($group['allowdeleteuser'])) { ?>
                    <dt class="mt10">删除用户</dt>
                    <dd class="mt10">
                        <button class="Button Button-primary" id="user_delete_<?php echo $_uid; ?>">删除用户&nbsp;&nbsp;<span class="red"><?php echo $_user['username']; ?></span></button>
                    </dd>
                    <?php } ?>
                </dl>
                
                <!-- 游客: 禁止IP -->
                <?php } else { ?>

                <dl class="user-profile">
                    <dt>用户名</dt>
                    <dd><?php echo $_user['username']; ?></dd>
                    <dt>用户组</dt>
                    <dd><?php echo $_user['groupname']; ?></dd>

                    <?php if($group['allowviewip']) { ?>
                    <dt>注册IP</dt>
                    <dd>IP：<?php echo $_ip; ?> <?php echo ($banip ? '[已禁止，截止日期：'.$banip['expiry_fmt'].']' : ''); ?></dd>
                    <?php } ?>

                    <?php if(!empty($group['allowbanuser'])) { ?>
                    <dt class="mt10">
                        <select id="day_<?php echo $_ip_url; ?>">
                            <option value="1">一天</option>
                            <option value="3">三天</option>
                            <option value="7">一周</option>
                            <option value="30">一月</option>
                            <option value="365">一年</option>
                            <option value="0">永久禁止</option>
                            <option value="-1">解除禁止</option>
                        </select>
                    </dt>
                    <dd class="mt10">
                        <button class="primary-btn" id="user_banip_<?php echo $_ip_url; ?>">禁止/解除 IP</button>
                    </dd>
                    <?php } ?>
                </dl>

            <?php } ?>

            </div>
        </div>
    </div>
    <div class="dashboard">

        <?php include "./pc/view/login_box.htm"; ?>

        <?php include "./pc/view/user_menu.inc.htm"; ?>
        
        <?php include "./pc/view/copyright.htm"; ?>

    </div>
    <div class="clear"></div>
</div>

<?php include "./pc/view/user_footer.inc.htm"; ?>

<script>

// 删除用户
var jsubmit = $('#user_delete_<?php echo $_uid; ?>');
jsubmit.off('click').on('click', function() {
    if(window.confirm('确定删除用户吗？')) {
        // 这里可能需要调用多次才能彻底删除用户。考虑超时。
        $.xpost('mod-deleteuser-<?php echo $_uid; ?>.htm', function(code, message) {
            if(code == 0) {
                jsubmit.button(message);
                setTimeout(function() {window.location.reload();}, 500);
            } else {
                $.alert(message);
                jsubmit.button('reset');
            }
        });
    }
});

// 禁止 ip
var jbansubmit = $('#user_banip_<?php echo $_ip_url; ?>');
var jday = $('#day_<?php echo $_ip_url; ?>');
jbansubmit.off('click').on('click', function() {
    // 这里可能需要调用多次才能彻底删除用户。考虑超时。
    $.xpost('mod-banip-<?php echo $_ip_url; ?>-'+xn_urlencode(jday.val())+'.htm', function(code, message) {
        if(code == 0) {
            jbansubmit.button(message);
            setTimeout(function() {window.location.reload();}, 500);
        } else {
            $.alert(message);
            jbansubmit.button('reset');
        }
    });
});
$('#user_menu').find('a').eq(0).class_active();

</script>